#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <queue>
using namespace std;
//int num;
//vector<int> v(num + 1);
//int main()
//{
//	cin >> num;
//	v[10] = 3;
//	return 0;
//}


int main() {
    long long n = 0, m = 0;
    cin >> n >> m;
    long long type = 0;
    vector<int> v(n + 1);
    priority_queue<int> q;
    while (n--)
    {
        int k = 0;
        cin >> k;
        if (v[k] == 0)
            type++;
        v[k]++;
    }
    //cout<<type<<endl;
    if (type > m)
    {
        cout << -1;
        return 0;
    }
    for (auto i : v)
    {
        q.push(i);
    }
    int key = m - type;
    //cout<<key<<endl;
    while (key--)
    {
        int k = q.top() / 2;
        int l = q.top() % 2;
        q.pop();
        q.push(k);
        if (l == 1)
        {
            q.push(k + 1);
        }
        else {
            q.push(k);
        }

    }
    cout << q.top();

    return 0;
}